<?php
//活动表

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class RiskCheckModel extends Model
{
    use HasFactory;

    protected $table = 'risk_check';

    protected function serializeDate(\DateTimeInterface $date)
    {
        return $date->format($this->dateFormat ?: 'Y-m-d H:i:s');
    }

    // 访问器
    protected function score(): Attribute
    {
        return new Attribute(
            get: fn ($value) => round($value / 100, 2),
            set: fn ($value) => $value * 100,
        );
    }

    /*protected function customizeField(): Attribute
    {
        return new Attribute(
            get: fn ($value) => json_decode($value, true),
        );
    }*/

    public function risk ()
    {
        return $this->belongsTo(RiskModel::class, 'risk_id', 'id');
    }
}
